"""
从SV_data中提取目标SV的物理区间
"""
import sys
import pandas as pd

SV_DATA_FILE_PATH=sys.argv[1]
SAMPLE_NAME=sys.argv[2]
TYPE_CODE=sys.argv[3]

FLANK = 500000

if __name__ == '__main__':
    sv_df = pd.read_csv(SV_DATA_FILE_PATH, low_memory=False)
    filter_sv_df = sv_df[(sv_df["check"]==True)&(sv_df["genome"]==SAMPLE_NAME)&(sv_df["type"] == TYPE_CODE)][["#reference","ref_start","ref_stop"]].copy()
    filter_sv_df["S"] = filter_sv_df["ref_start"].apply(lambda x: x - FLANK if x > FLANK else 0)
    filter_sv_df["E"] = filter_sv_df["ref_stop"].apply(lambda x: x + FLANK)

    filter_sv_df[["#reference", "S", "E"]].to_csv(f"./{SAMPLE_NAME}.{TYPE_CODE}.bed", index=False, header=None, sep="\t")
